import com.netflix.zuul.ZuulFilter
import com.netflix.zuul.context.RequestContext
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.nio.charset.Charset

/**
 * Created by chengxi on 2017/8/26.
 */
class PreFilter extends ZuulFilter{

    Logger logger = LoggerFactory.getLogger(PreFilter.class)

    @Override
    String filterType() {
        return "post"
    }

    @Override
    int filterOrder() {
        return 2000
    }

    @Override
    boolean shouldFilter() {
        return true
    }

    @Override
    Object run() {
        logger.info("这个是一个Post过滤器")
        HttpServletResponse response = RequestContext.getCurrentContext().getResponse()
        response.getOutputStream().write("这是Post请求".getBytes(Charset.forName("utf-8")))
        response.flushBuffer()
    }
}